{
 "cells": [
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-11T03:01:33.628023Z",
     "start_time": "2025-09-11T03:01:33.500691Z"
    }
   },
   "cell_type": "code",
   "source": "import numpy as np",
   "id": "8ac9377017bcd363",
   "outputs": [],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-11T03:01:33.652363Z",
     "start_time": "2025-09-11T03:01:33.629053Z"
    }
   },
   "cell_type": "code",
   "source": [
    "A = np.array([[1,1],[2,2],[0,0]])\n",
    "U,S,V = np.linalg.svd(A)\n",
    "print(U)\n",
    "print(S)\n",
    "print(V)"
   ],
   "id": "d1f56570dcb7cd53",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-0.4472136  -0.89442719  0.        ]\n",
      " [-0.89442719  0.4472136   0.        ]\n",
      " [ 0.          0.          1.        ]]\n",
      "[3.16227766e+00 1.57009246e-16]\n",
      "[[-0.70710678 -0.70710678]\n",
      " [-0.70710678  0.70710678]]\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-11T03:03:43.957433Z",
     "start_time": "2025-09-11T03:03:43.248534Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from sklearn.utils.extmath import randomized_svd\n",
    "U,S,V = randomized_svd(A,n_components=2)\n",
    "print(U)\n",
    "print(S)\n",
    "print(V)"
   ],
   "id": "89ca32ed85373c94",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.4472136   0.89442719]\n",
      " [ 0.89442719 -0.4472136 ]\n",
      " [ 0.         -0.        ]]\n",
      "[3.16227766 0.        ]\n",
      "[[ 0.70710678  0.70710678]\n",
      " [ 0.70710678 -0.70710678]]\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-11T03:11:53.333503Z",
     "start_time": "2025-09-11T03:11:53.185195Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from sklearn.decomposition import PCA\n",
    "X = np.random.randn(100,3)\n",
    "pca = PCA(n_components=2)\n",
    "X_pca = pca.fit_transform(X)\n",
    "print(X_pca.shape)"
   ],
   "id": "948a76c12e819459",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(100, 2)\n"
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "b6746ff498ada51e"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
